import 'package:fluent_ui/fluent_ui.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import '../controller/system/user_controller.dart';
import 'package:flutter/material.dart' as m;
import '../pages/login.dart';
import '../pages/main_page.dart';


Map<String, WidgetBuilder> routeList={
  "/login": (_) => Login(),
  "/home": (_) => const MainPage()
};

Route routeGenerator(RouteSettings settings) {
  final userController = Get.find<UserController>();
  final name = settings.name;
  WidgetBuilder? builder = routeList[name];
  userController.checkIsLogin();
  if (settings.name!="/login" && !userController.isLogin){
    builder= (_) => Login();
  }
  builder ??= (content) =>  Login();
  final route = m.MaterialPageRoute(
    builder: builder,
    settings: settings,
  );
  return route;
}